<?php
/**
 * Created by PhpStorm.
 * User: 伟鑫
 * Date: 2019/3/11
 * Time: 15:30
 */

namespace app\admin\model;


use think\Db;
use think\Model;

class ShifuModel extends Model
{
    protected $name = 'member';


    public function edit(){
        try{
            $param = input();
            if (!empty($param['baozhenjin']) > 0){
                $member = $this->get($param['id']);
                $member->baozhenjin = $member->baozhenjin -$param['baozhenjin'];
                if ($member->save()){

                    $ticheng = db('ticheng')->where(['userid',session('userid'), 'ticheng' =>4])->order('id desc')->limit(1)->select();
                    $qianbao['userid'] = session('userid');
                    $qianbao['type'] = 2;
                    $qianbao['remark'] = '平台扣除保证金';
                    $qianbao['money'] = $param['baozhenjin'];
                    $qianbao['addtime'] = time();
                    $qianbao['ticheng'] = 4;
                    $qianbao['after'] = $ticheng[0]['after'] - $param['baozhenjin'];//求改变后的量
                    //添加钱包记录
                    db('ticheng')->where('userid',session('userid'))->insertGetId($qianbao);
                    return msg(1,url('index'),'修改成功');
                }
            }
        }catch (\Exception $e){
            return msg(-1,[],'修改失败');
        }

    }
    //服务技能
    protected function getFenleiidAttr($v){
        $data = Db::name('fenlei')->where('id','in',$v)->select();
        return join('||',array_column($data,'name'));
    }

    //服务区域
    protected function getXianAttr($v){
        $data = Db::name('area')->where('id','in',$v)->select();
        return join('||',array_column($data,'name'));
    }
    //身份证
    protected function getImgAttr($v){
        return explode(',',$v);
    }
    //技能证书
    protected function getImgsAttr($v){
        return explode(',',$v);
    }

}